/**
 * @Description : 向 Vuex 提供方法名
 * @author : August_xiao 1932794922@qq.com
 * @date : 2022-02-27 15:41
 */

import * as types from '@/store/mutation-types'
import { defaultConfiguration } from '@/assets/config/configuration.js'

const mutations = {
  /**
   * 图片
   * @param state
   * @param payload url
   */
  [types.CHANGED_EFAULT_ERROR_IMAGE_URL](state, payload) {
    // 获取不到,则从配置文件取
    if (!payload) {
      payload = defaultConfiguration.defaultErrorImageUrl
    }
    // 变更状态
    state.defaultErrorImageUrl = payload
  },

  /**
   * 修改滑动滚动
   * @param state
   * @param payload 对象
   */
  [types.CHANGED_INFINITE_SCROLL_DISTANCE](state, payload) {
    state.load.infiniteScrollDistance = payload.infiniteScrollDistance
    state.load.isLoad = payload.isLoad
  },

  /**
   * 修改评论框显示
   * @param state
   * @param payload boolean
   */
  [types.IS_SHOW_ARTICLE_COMMENT](state, payload) {
    state.isShowArticleComment = payload
  },

  /**
   * 缓存路由菜单
   * @param state
   * @param payload
   */
  [types.SET_NAV_ROUTE](state, payload) {
    state.navList = payload
  },
  /**
   * 记录滚动条位置
   * @param state
   * @param payload
   */
  [types.RECORD_SCROLL_POSITION](state, payload) {
    state.scrollPoison = payload
  },

  /**
   * 记录当前主题
   * @param state
   * @param payload
   */
  [types.RECORD_SET_THEME](state, payload) {
    // 如果切换为黑色主题,则把背景图去掉
    if (!payload) {
      $('body').css('background-image', 'none')
      $('html').css('background', 'none')
    }
    state.theme = payload
  }
}

export default mutations
